package com.leyou.item.web;

import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

// 加入了CrossOrigin注解：自动在头信息中带有允许跨域的标记
// @CrossOrigin("*") // 允许所有的域来跨
//@CrossOrigin({"http://manage.leyou.com","http://www.leyou.com"}) // 允许manage.leyou.com、www.leyou.com域来跨
@RestController
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 根据父id查询分类
     * @param pid       父id
     * @return          分类dto的集合
     */
    @GetMapping("/category/of/parent")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByParentId(@RequestParam("pid") Long pid){
        return ResponseEntity.ok(categoryService.queryCategoryByParentId(pid));
    }
}
